package com.jalarbee.web.jsf.controller;

import java.io.IOException;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 *
 * @author Abdoulaye <b>Ikhnaton</b> Diallo
 */

@Named
@RequestScoped
public class LoginController {

    private static String SPRING_SECURITY_LOGIN_PROCESSING_URL = "/j_spring_security_check";

    public LoginController() {
    }
    
    public String login() throws ServletException, IOException {
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        RequestDispatcher requestDispatcher = ((ServletRequest)externalContext.getRequest()).getRequestDispatcher(SPRING_SECURITY_LOGIN_PROCESSING_URL);
        requestDispatcher.forward((ServletRequest)externalContext.getRequest(), (ServletResponse)externalContext.getResponse());
        FacesContext.getCurrentInstance().responseComplete();
        return null;
    }
}
